package web.validator;

import org.springframework.stereotype.Service;
import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;

import web.form.SearchForm;

@Service
public class SearchValidator implements Validator {
	
	public void validate(Object obj, Errors errors) {
		SearchForm search = (SearchForm) obj;
		
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "sheetCode", "error.code.required");
		
		if (search.getSheetType().compareTo("NONE")==0){
			errors.rejectValue("sheetType", "error.type.required");
		}
	}
	
	
	@Override
	public boolean supports(Class<?> clazz) {
		return SearchForm.class.isAssignableFrom(clazz);
	}
}
